home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Memory / Memory.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.9 KB  |  521 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import java.awt.event.MouseMotionListener;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLEncoder;
  15.  
  16. public class Memory extends Applet implements Runnable, MouseListener, MouseMotionListener {
  17.    private Thread thread;
  18.    private Image buffer;
  19.    private Image backImage;
  20.    private Image[] image;
  21.    private Image turnedImage;
  22.    // $FF: renamed from: b java.awt.Graphics
  23.    private Graphics field_0;
  24.    private boolean loaded;
  25.    private int wiBack;
  26.    private int heBack;
  27.    private boolean isBackImage = false;
  28.    // $FF: renamed from: N int
  29.    private int field_1 = 1;
  30.    // $FF: renamed from: wi int
  31.    private int field_2;
  32.    // $FF: renamed from: he int
  33.    private int field_3;
  34.    private int wiIm;
  35.    private int heIm;
  36.    private int pause = 50;
  37.    private int NCol = 1;
  38.    private int NRow;
  39.    private String[] image_string;
  40.    private String backImageName;
  41.    private Color backColor;
  42.    private String statusBarText;
  43.    private AudioClip sound;
  44.    private AudioClip clicSound;
  45.    private AudioClip enterSound;
  46.    private boolean loopSound;
  47.    private String link;
  48.    private Color turnedColor;
  49.    private int[][] mat;
  50.    private int[][] ret;
  51.    private int wiSpace;
  52.    private int heSpace;
  53.    private boolean hand = false;
  54.    private int lastClic;
  55.    private int iLast;
  56.    private int jLast;
  57.    private boolean change;
  58.    // $FF: renamed from: I int
  59.    private int field_4;
  60.    // $FF: renamed from: J int
  61.    private int field_5;
  62.  
  63.    public String getAppletInfo() {
  64.       return "Name: Memory\r\nAuthor: Taiji Software\r\n";
  65.    }
  66.  
  67.    public Memory() {
  68.       this.turnedColor = Color.black;
  69.       ((Component)this).addMouseListener(this);
  70.       ((Component)this).addMouseMotionListener(this);
  71.    }
  72.  
  73.    public void register() {
  74.       try {
  75.          URL u = new URL("http://www.taijisoftware.com");
  76.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  77.       } catch (Exception e) {
  78.          System.out.println(e);
  79.          this.stop();
  80.       }
  81.    }
  82.  
  83.    public void init() {
  84.       String codeBase = null;
  85.  
  86.       try {
  87.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  88.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  89.          codeBase = codeBase.toUpperCase();
  90.       } catch (Exception var11) {
  91.       }
  92.  
  93.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  94.          String regCode = ((Applet)this).getParameter("registration_code");
  95.          if (regCode == null) {
  96.             regCode = ((Applet)this).getParameter("reg_domain");
  97.             if (regCode == null) {
  98.                this.register();
  99.             } else {
  100.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  101.                   codeBase = "WWW." + codeBase;
  102.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  103.                   codeBase = codeBase.substring(4);
  104.                }
  105.  
  106.                char[] chars = new char[codeBase.length()];
  107.                codeBase.getChars(0, codeBase.length(), chars, 0);
  108.                String key = new String("haricot");
  109.                char[] chars2 = new char[key.length()];
  110.                key.getChars(0, key.length(), chars2, 0);
  111.  
  112.                for(int i = 0; i < codeBase.length(); ++i) {
  113.                   int j;
  114.                   if (i >= key.length()) {
  115.                      j = i - key.length() * (i / key.length());
  116.                   } else {
  117.                      j = i;
  118.                   }
  119.  
  120.                   chars[i] += chars2[j];
  121.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  122.                }
  123.  
  124.                String res = new String(chars);
  125.                if (!res.equalsIgnoreCase(regCode)) {
  126.                   this.register();
  127.                }
  128.             }
  129.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  130.             this.register();
  131.          }
  132.       }
  133.  
  134.       this.getParameters();
  135.       this.NRow = (int)((float)(2 * this.field_1) / (float)this.NCol);
  136.       if (2 * this.field_1 % this.NCol != 0) {
  137.          ++this.NRow;
  138.       }
  139.  
  140.       this.mat = new int[this.NRow][this.NCol];
  141.       this.ret = new int[this.NRow][this.NCol];
  142.       int n = 1;
  143.       int c = 0;
  144.  
  145.       for(int i = 0; i < this.NRow; ++i) {
  146.          for(int j = 0; j < this.NCol; ++j) {
  147.             this.ret[i][j] = 0;
  148.             if (n == this.field_1 + 1) {
  149.                this.mat[i][j] = 0;
  150.             } else {
  151.                this.mat[i][j] = n;
  152.                if (c == 1) {
  153.                   ++n;
  154.                }
  155.  
  156.                c = 1 - c;
  157.             }
  158.          }
  159.       }
  160.  
  161.       for(int k = 0; k < 500; ++k) {
  162.          int i1 = (int)(Math.random() * (double)this.NRow);
  163.          int j1 = (int)(Math.random() * (double)this.NCol);
  164.          int i2 = (int)(Math.random() * (double)this.NRow);
  165.          int j2 = (int)(Math.random() * (double)this.NCol);
  166.          if (this.mat[i1][j1] != 0 && this.mat[i2][j2] != 0) {
  167.             int b = this.mat[i1][j1];
  168.             this.mat[i1][j1] = this.mat[i2][j2];
  169.             this.mat[i2][j2] = b;
  170.          } else {
  171.             --k;
  172.          }
  173.       }
  174.  
  175.       if (this.sound != null) {
  176.          if (this.loopSound) {
  177.             this.sound.loop();
  178.             return;
  179.          }
  180.  
  181.          this.sound.play();
  182.       }
  183.  
  184.    }
  185.  
  186.    public void getParameters() {
  187.       this.field_2 = ((Component)this).getSize().width;
  188.       this.field_3 = ((Component)this).getSize().height;
  189.  
  190.       for(this.field_1 = 0; ((Applet)this).getParameter("image" + Integer.toString(this.field_1 + 1)) != null; ++this.field_1) {
  191.       }
  192.  
  193.       this.image_string = new String[this.field_1];
  194.  
  195.       for(int i = 0; i < this.field_1; ++i) {
  196.          this.image_string[i] = ((Applet)this).getParameter("image" + Integer.toString(i + 1));
  197.       }
  198.  
  199.       String s = ((Applet)this).getParameter("pause");
  200.       if (s != null) {
  201.          this.pause = Integer.parseInt(s);
  202.       }
  203.  
  204.       s = ((Applet)this).getParameter("columns_number");
  205.       if (s != null) {
  206.          this.NCol = Integer.parseInt(s);
  207.       }
  208.  
  209.       if (((Applet)this).getParameter("turned_color") != null) {
  210.          this.turnedColor = this.getColor("turned_color");
  211.       }
  212.  
  213.       this.backImageName = ((Applet)this).getParameter("background_image");
  214.       if (this.backImageName != null) {
  215.          this.isBackImage = true;
  216.       }
  217.  
  218.       ((Component)this).setBackground(this.getColor("background_color"));
  219.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  220.       s = ((Applet)this).getParameter("sound_name");
  221.       if (s != null) {
  222.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  223.       }
  224.  
  225.       s = ((Applet)this).getParameter("loop_sound");
  226.       if (s != null) {
  227.          if (s.equals("yes")) {
  228.             this.loopSound = true;
  229.          } else {
  230.             this.loopSound = false;
  231.          }
  232.       }
  233.  
  234.       s = ((Applet)this).getParameter("clic_sound_name");
  235.       if (s != null) {
  236.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  237.       }
  238.  
  239.       this.link = ((Applet)this).getParameter("link");
  240.    }
  241.  
  242.    public Color getColor(String param) {
  243.       String s = ((Applet)this).getParameter(param);
  244.       if (s != null) {
  245.          if (s.substring(0, 1).equals("#")) {
  246.             s = s.substring(1);
  247.             int i = Integer.parseInt(s, 16);
  248.             return new Color(i);
  249.          } else {
  250.             return null;
  251.          }
  252.       } else {
  253.          return null;
  254.       }
  255.    }
  256.  
  257.    public final void paint(Graphics g) {
  258.       if (this.loaded) {
  259.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  260.          if (this.isBackImage) {
  261.             this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  262.          }
  263.  
  264.          for(int i = 0; i < this.NRow; ++i) {
  265.             for(int j = 0; j < this.NCol; ++j) {
  266.                if (this.mat[i][j] != 0) {
  267.                   if (this.ret[i][j] == 0) {
  268.                      if (this.turnedImage != null) {
  269.                         this.field_0.drawImage(this.turnedImage, this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm, this);
  270.                      } else {
  271.                         this.field_0.fillRect(this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm);
  272.                      }
  273.                   } else {
  274.                      this.field_0.drawImage(this.image[this.mat[i][j] - 1], this.wiSpace + j * (this.wiSpace + this.wiIm), this.heSpace + i * (this.heSpace + this.heIm), this.wiIm, this.heIm, this);
  275.                   }
  276.                }
  277.             }
  278.          }
  279.  
  280.          g.drawImage(this.buffer, 0, 0, this);
  281.          if (this.change) {
  282.             this.sleep(1000);
  283.             this.ret[this.iLast][this.jLast] = 0;
  284.             this.ret[this.field_4][this.field_5] = 0;
  285.             this.lastClic = 0;
  286.             this.change = false;
  287.          }
  288.       }
  289.  
  290.    }
  291.  
  292.    public final void update(Graphics g) {
  293.       this.paint(g);
  294.    }
  295.  
  296.    public void start() {
  297.       if (this.thread == null) {
  298.          this.thread = new Thread(this);
  299.          this.thread.start();
  300.       }
  301.  
  302.    }
  303.  
  304.    public void stop() {
  305.       if (this.thread != null) {
  306.          this.thread = null;
  307.       }
  308.  
  309.       if (this.sound != null) {
  310.          this.sound.stop();
  311.       }
  312.  
  313.    }
  314.  
  315.    public void run() {
  316.       if (!this.loaded) {
  317.          this.image = new Image[this.field_1];
  318.          MediaTracker tracker = new MediaTracker(this);
  319.  
  320.          for(int i = 0; i < this.field_1; ++i) {
  321.             this.image[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string[i]);
  322.          }
  323.  
  324.          for(int i = 0; i < this.field_1; ++i) {
  325.             tracker.addImage(this.image[i], 0);
  326.          }
  327.  
  328.          if (this.isBackImage) {
  329.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  330.             tracker.addImage(this.backImage, 0);
  331.          }
  332.  
  333.          if (((Applet)this).getParameter("turned_image") != null) {
  334.             this.turnedImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("turned_image"));
  335.             tracker.addImage(this.turnedImage, 0);
  336.          }
  337.  
  338.          try {
  339.             tracker.waitForAll();
  340.             this.loaded = !tracker.isErrorAny();
  341.          } catch (Exception e) {
  342.             System.out.println(e);
  343.          }
  344.  
  345.          if (!this.loaded) {
  346.             this.stop();
  347.          }
  348.       }
  349.  
  350.       this.wiIm = this.field_2;
  351.       this.heIm = this.field_3;
  352.  
  353.       for(int i = 0; i < this.field_1; ++i) {
  354.          if (this.image[i].getWidth(this) < this.wiIm) {
  355.             this.wiIm = this.image[i].getWidth(this);
  356.          }
  357.  
  358.          if (this.image[i].getHeight(this) < this.heIm) {
  359.             this.heIm = this.image[i].getHeight(this);
  360.          }
  361.       }
  362.  
  363.       this.wiSpace = (int)((float)(this.field_2 - this.NCol * this.wiIm) / (float)(this.NCol + 1));
  364.       this.heSpace = (int)((float)(this.field_3 - this.NRow * this.heIm) / (float)(this.NRow + 1));
  365.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  366.       this.field_0 = this.buffer.getGraphics();
  367.       this.field_0.setColor(this.turnedColor);
  368.       if (this.isBackImage) {
  369.          this.wiBack = this.backImage.getWidth(this);
  370.          this.heBack = this.backImage.getHeight(this);
  371.       }
  372.  
  373.       while(true) {
  374.          ((Component)this).repaint();
  375.          this.sleep(this.pause);
  376.       }
  377.    }
  378.  
  379.    public void sleep(int pause) {
  380.       try {
  381.          Thread.sleep((long)pause);
  382.       } catch (InterruptedException var2) {
  383.          this.stop();
  384.       }
  385.    }
  386.  
  387.    public URL giveURL(String url) {
  388.       try {
  389.          if (url.toUpperCase().startsWith("HTTP")) {
  390.             return new URL(url);
  391.          } else if (url.toUpperCase().startsWith("FTP")) {
  392.             int p = url.indexOf(":");
  393.             int p2 = url.indexOf(":", p + 1);
  394.             if (p2 != -1) {
  395.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  396.             }
  397.  
  398.             p = url.indexOf("%40");
  399.             if (p != -1) {
  400.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  401.             }
  402.  
  403.             return new URL(url);
  404.          } else {
  405.             return new URL(((Applet)this).getCodeBase(), url);
  406.          }
  407.       } catch (MalformedURLException e) {
  408.          System.out.println(e);
  409.          return null;
  410.       }
  411.    }
  412.  
  413.    public void mouseClicked(MouseEvent e) {
  414.       if (this.clicSound != null) {
  415.          this.clicSound.play();
  416.       }
  417.  
  418.       int x = e.getX();
  419.       int y = e.getY();
  420.  
  421.       for(int i = 0; i < this.NRow; ++i) {
  422.          for(int j = 0; j < this.NCol; ++j) {
  423.             if (x >= this.wiSpace + j * (this.wiSpace + this.wiIm) && x <= (j + 1) * (this.wiSpace + this.wiIm) && y >= this.heSpace + i * (this.heSpace + this.heIm) && y <= (i + 1) * (this.heSpace + this.heIm)) {
  424.                if (this.mat[i][j] == 0) {
  425.                   return;
  426.                }
  427.  
  428.                if (this.ret[i][j] == 0) {
  429.                   this.ret[i][j] = 1;
  430.                   if (this.lastClic == 0) {
  431.                      this.lastClic = this.mat[i][j];
  432.                      this.iLast = i;
  433.                      this.jLast = j;
  434.                      return;
  435.                   }
  436.  
  437.                   if (this.lastClic != this.mat[i][j]) {
  438.                      this.change = true;
  439.                      this.field_4 = i;
  440.                      this.field_5 = j;
  441.                      ((Component)this).repaint();
  442.                      return;
  443.                   }
  444.  
  445.                   this.lastClic = 0;
  446.                   boolean flag = false;
  447.  
  448.                   for(int ii = 0; ii < this.NRow; ++ii) {
  449.                      for(int jj = 0; jj < this.NCol; ++jj) {
  450.                         if (this.ret[ii][jj] == 0 && this.mat[ii][jj] != 0) {
  451.                            flag = true;
  452.                         }
  453.                      }
  454.                   }
  455.  
  456.                   if (!flag && this.link != null) {
  457.                      String target = ((Applet)this).getParameter("target");
  458.                      if (target == null) {
  459.                         target = "_blank";
  460.                      }
  461.  
  462.                      URL u = this.giveURL(this.link);
  463.                      ((Applet)this).getAppletContext().showDocument(u, target);
  464.                   }
  465.                }
  466.  
  467.                return;
  468.             }
  469.          }
  470.       }
  471.  
  472.    }
  473.  
  474.    public void mouseEntered(MouseEvent e) {
  475.       if (this.statusBarText != null) {
  476.          ((Applet)this).showStatus(this.statusBarText);
  477.       }
  478.  
  479.    }
  480.  
  481.    public void mouseExited(MouseEvent e) {
  482.    }
  483.  
  484.    public void mousePressed(MouseEvent e) {
  485.    }
  486.  
  487.    public void mouseReleased(MouseEvent e) {
  488.    }
  489.  
  490.    public void mouseDragged(MouseEvent e) {
  491.    }
  492.  
  493.    public void mouseMoved(MouseEvent e) {
  494.       int x = e.getX();
  495.       int y = e.getY();
  496.  
  497.       for(int i = 0; i < this.NRow; ++i) {
  498.          for(int j = 0; j < this.NCol; ++j) {
  499.             if (x >= this.wiSpace + j * (this.wiSpace + this.wiIm) && x <= (j + 1) * (this.wiSpace + this.wiIm) && y >= this.heSpace + i * (this.heSpace + this.heIm) && y <= (i + 1) * (this.heSpace + this.heIm)) {
  500.                if (this.mat[i][j] == 0) {
  501.                   return;
  502.                }
  503.  
  504.                if (!this.hand) {
  505.                   ((Component)this).setCursor(new Cursor(0));
  506.                   this.hand = true;
  507.                }
  508.  
  509.                return;
  510.             }
  511.          }
  512.       }
  513.  
  514.       if (this.hand) {
  515.          ((Component)this).setCursor(new Cursor(0));
  516.          this.hand = false;
  517.       }
  518.  
  519.    }
  520. }
  521.